package com.alibaba.demo.service.executor.command;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.demo.domain.service.entity.IotServiceEntity;
import com.alibaba.demo.domain.service.gateway.IotServiceGateway;
import com.alibaba.demo.dto.clientobject.service.IotServiceCO;
import com.alibaba.demo.dto.command.IotServiceAddCmd;
import com.alibaba.demo.service.assembler.IotServiceAssembler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Administrator
 * @date 2024/4/28 10:01
 * @description
 */
@Slf4j
@Component
public class IotServiceAddCmdExe {

    @Resource
    private IotServiceGateway iotServiceGateway;
    @Resource
    private IotServiceAssembler iotServiceAssembler;

    public Response execute(IotServiceAddCmd cmd) {
        IotServiceEntity iotServiceEntity = iotServiceAssembler.toEntity(cmd);
        IotServiceEntity saveResult = iotServiceGateway.save(iotServiceEntity);
        IotServiceCO iotServiceCO = iotServiceAssembler.toCo(saveResult);
        return SingleResponse.of(iotServiceCO);
    }
}
